/**
 * Created by yangrourou on 16/11/14.
 */
var indexController = new Vue({
    el: '#indexPage',
    data: {
        request: new requestController(),
        messages: [],
        cps:'commonList',
        alerts:'',
        listData:[],
        listTitle:[],
        mainMenu:{},
        userName:'',
        currentPage:'',
        app:'',
        model:'',
        requestModel:'',
        loading:false/*加载动画显示*/
    },
    components:{
        "commonList":commonList,
        "publishNews":publishNews,
        "commonDialogAlert":commonDialogAlert,
        "commonDialogInput":commonDialogInput,
        "publishNews":publishNews
    },
    mounted:function(){
        console.log('主vue实例加载完成');
        var _this = this;

        var menuJson = _this.request.getJsonModel('public','pcmenu');
        
        console.log(JSON.stringify(menuJson));
        for(i in menuJson){
            menuJson[i].open = false;
        }

        this.mainMenu = menuJson;
        

        try{
            setTimeout(function(){
                $('.mk-menu li').eq(0).find('div').trigger('click')
                $('.mk-menu li').eq(0).find('li').eq(0).trigger('click');
            },500)
        }catch(e){
            console.log('没有点击啊')
        }

        this.userName = window.localStorage.name || "众创空间-未知";

        //判断token是否存在
        if(!localStorage.token){
            window.location = '/app/index/view/loginView.php'
        }
    },
    methods:{
        autoLogin:function () {
            var _self = this;
            var jsonData = {};
            jsonData.uid = _self.request.getCache('uid');
            jsonData.password = _self.request.getCache('password');
            jsonData.channel = 1;
            jsonData.appType = 2;
            jsonData.appVersion = 100;
            _self.request.setApiName('/User/Logon/UID');
            _self.request.setRequest(jsonData);
            _self.request.post();
            var resData = _self.request.getResponse();
            if(resData.uid != null && resData.uid != ''){
                _self.request.setCache('uid',resData.uid);
                console.log(_self.request.getCache('uid'));
                //window.location = '/index.php';
            }
        },
        initClick:function(){
            $('.mk-menu li').eq(0).find('li').eq(0).trigger('click')
        },
        logOut:function(){
            this.request.clearCache();
            alert('退出成功！');
            window.location = '/app/index/view/loginView.php';
        }
    }

});